# Maintainer: Daurnimator <daurnimator@archlinux.org>

pkgname=("lua-luassert" "lua53-luassert" "lua52-luassert" "lua51-luassert")
pkgver=1.9.0
pkgrel=1
_rockrel=1
pkgdesc='Assertion library for Lua'
arch=('any')
url='https://github.com/lunarmodules/luassert'
license=('MIT')
makedepends=('luarocks'
             # https://github.com/luarocks/luarocks/issues/1275
             'lua51'
             'lua52'
             'lua53'
             'lua')
_archive="luassert-$pkgver"
source=("$url/archive/v$pkgver/$_archive.tar.gz")
sha256sums=('1db0fabf1bd87392860375b89a8a37d17b687325c988be0df8c42e7e96e7ed73')

build() {
    cd "$_archive"
    for v in 5.1 5.2 5.3 5.4; do
        mkdir -p "$v/"
        luarocks make --pack-binary-rock --lua-version="$v" --deps-mode=none rockspecs/$_archive-$_rockrel.rockspec
        mv "$_archive-$_rockrel".*.rock "$v/"
    done
}

_package() {
    pkgdesc+=" for Lua $1"
    cd "$_archive"
    depends+=("${pkgname%-*}" "${pkgname%-*}-say")
    luarocks install --lua-version="$1" --tree="$pkgdir/usr/" --deps-mode=none --no-manifest "$1"/*.rock
    install -Dm0644 -t "$pkgdir/usr/share/licenses/$pkgname/" LICENSE
}

package_lua51-luassert() {
    _package 5.1
}

package_lua52-luassert() {
    _package 5.2
}

package_lua53-luassert() {
    _package 5.3
}

package_lua-luassert() {
    _package 5.4
}
